<template>
  <div class="content_box" v-loading="loading">
    <div class="main-box">
      <p class="main-title">选择对公银行卡</p>
      
      <div class="list" v-for="(item,index) in list"  @click="changeTab(index)">
        <div class="box">
          <div>
            <p>收款单位：</p>
            <p>{{item.bank_username}}</p>
          </div>
          <div>
            <p>对公银行卡卡号：</p>
            <p>{{item.bank_num}}</p>
          </div>
        </div>

        <p :class="tabIndex == index?'quan on':'quan'"><span></span></p>
      </div>

      
      <div class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button
          :disabled="tabIndex == -1"
          type="primary"
          @click="submit"
        >
          确认选择
        </el-button>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reactive, ref, computed,onMounted } from "vue";
import { ElNotification } from "element-plus";
import { getPublicBank } from "@/api/bond/refund";

const props = defineProps({
  bailId: {
    type: Number,
  },
  id: {
    type: Number,
  },
});

onMounted(() => {
  tabIndex.value = -1
  getList()
});

const emit = defineEmits(['closeDrawer','changeSubmit']);

const updateForms = ref();

let loading = ref(false)
let list = ref([])
const getList =()=>{
  loading.value = true
  getPublicBank({step:3}).then(res=>{
    if(res.code == 1){
      list.value = res.data
      loading.value = false
    }else{
      loading.value = false
    }
  })
}

// 关闭
const close=()=>{
  emit("closeDrawer");
}

// 确认
const submit=()=>{
  let obj = list.value[tabIndex.value]
  emit("changeSubmit",obj);
  close()
}

let tabIndex = ref(-1)
const changeTab = (index: number)=>{
  tabIndex.value = index
}
</script>
<style scoped lang="scss">
.dialog-footer {
  margin-top:50px;
  text-align: center;
}
.main-box{
  min-height: auto;
  ::v-deep .el-dialog__header{
      padding:0
  }
}
.main-text{
  margin:20px 0 47px 0;
  font-size: 14px;
  color: #323C4F;
}

.list{
  border-radius: 8px;
  background: #F8F8F8;
  border: 1px solid #EAEAEA;
  padding:10px 18px;
  margin-top:17px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .box{
    div{
    display: flex;
      line-height: 34px;
      p{
        font-size: 14px;
        color: #3D3D3D;
        &:first-child{
          width: 130px;
        }
      }
    }
  }
  
  .quan{
    width: 16px;
    height: 16px;
    border: 1px solid #D8D8D8;
    border-radius: 50%;
    margin-right:8px;
    &.on{
      background: #1C55D1;
      border-color:#1C55D1;
      display: flex;
      align-items: center;
      justify-content: center;
      span{
        display: inline-block;
        width: 6px;
        height: 6px;
        background: #fff;
        border-radius: 50%;
      }
    }
  }
}
</style>
  